package com.coderman.common.starter.nacos.datadict.data;

import java.util.ArrayList;
import java.util.Collection;

/**
 * 自定义list
 * @author fcs
 * @param <E>
 */
public class StrictList<E> extends ArrayList {
    private final String name;

    public StrictList(String name, int initialCapacity) {
        super(initialCapacity);
        this.name = name;
    }

    public StrictList(String name) {
        super();
        this.name = name;
    }


    public StrictList(String name, Collection<? extends E> m) {
        super(m);
        this.name = name;
    }


    @Override
    public boolean add(Object value) {
        if (super.contains(value)) {
            throw new IllegalArgumentException(name + " already contains value for " + value);
        }
        return super.add(value);
    }
}
